package com.macro.mall.service.impl;

import com.macro.mall.mapper.OmsOrderReviewMapper;
import com.macro.mall.model.PmsProductComment;
import com.macro.mall.service.OmsOrderReviewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.Future;

@Service
public class OmsOrderReviewServiceImpl implements OmsOrderReviewService {
    @Autowired
    private OmsOrderReviewMapper mapper;
    /**
     * 查看
     */
    @Override
    public List<PmsProductComment> lookComment(Integer id) {
        List<PmsProductComment> list = mapper.lookComment(id);
        return list;
    }
    /**
     * 添加评论
     */
    @Override
    @Async
    public void addComment(PmsProductComment comment) {
        mapper.addComment(comment);
        Integer id = comment.getId();
        try {
            //添加评论中间表
            title(id);
            //添加评论视图表
            addView(comment.getSkuId());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    @Override
    @Async
    public Future<Integer> title(int id) {
        //查询标签表
        List<Long> ids =  mapper.title(id);
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        //添加 评论中间表
        mapper.addCommentTitle(id,ids);
        return new AsyncResult<>(3000);
    }

    @Override
    @Async
    public Future<Integer> addView(int id) {
        //添加评论视图表
        String img="https://mall-bw.oss-cn-shanghai.aliyuncs.com/2024/OCTOBER/3/19/17/7eb1dea1-6ec9-4671-ae0e-747ad46ce823.png";
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        mapper.addView(id,img,1);
        return new AsyncResult<>(1000);
    }



    /**
     * 删除
     */
    @Override
    public void delComment(Integer id) {
        mapper.delComment(id);
    }


}
